package com.storm.future;

import com.storm.future.advisor.Repair;
import com.storm.future.config.MainConfig;
import com.storm.future.red.common.EngineerSoldier;
import org.springframework.aop.Advisor;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author gu
 * @date 2020/3/3 9:55
 */
public class App {

	/**
	 * 获取所有bean定义的方法，在bean初始化之前就可以获得
	 * 该功能极其强悍，可以扫描所有bean，然后获得bean的元信息
	 * 检查它们是不是切面，然后获取切面
	 * */
	public static String[] getAllBeanDefinition(ListableBeanFactory beanFactory){
		String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
				beanFactory, Object.class, true, false);
		return beanNames;
	}

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig.class);
		EngineerSoldier bean = context.getBean(EngineerSoldier.class);
		bean.attack(null);
		Class<?>[] interfaces = bean.getClass().getInterfaces();
		for (Class<?> anInterface : interfaces) {
			System.out.println(anInterface);
		}
		Repair repair = (Repair)bean;
		repair.repair();
	}
}
